package com.fadadianqi.logistics.admin.ticket.service;

import com.fadadianqi.logistics.admin.ticket.dao.PrizeDAO;
import com.fadadianqi.logistics.admin.ticket.model.Prize;
import com.fadadianqi.commons.PrimaryKeyCreator;
import com.yeqiangwei.commons.util.Pagination;
import com.yeqiangwei.commons.util.ValidatorHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class PrizeService {


    public void save(Prize prize) {
        if (ValidatorHelper.isEmpty(prize.getId())) {
            prize.setId(PrimaryKeyCreator.create());
            prizeDAO.create(prize);
        } else {
            prizeDAO.update(prize);
        }
    }

    public List<Prize> findAll(Pagination pagination) {
        pagination.setOrderList(new Pagination.Order[]{
                Pagination.getNewOrder("withdraw", Boolean.TRUE),
                Pagination.getNewOrder("value", Boolean.FALSE) // 按照奖品价值排名
        });
        return prizeDAO.findAll(pagination);
    }

    public List<Prize> findAllWithNotDraw(Pagination pagination) {
        pagination.setOrderList(new Pagination.Order[]{
                Pagination.getNewOrder("withdraw", Boolean.TRUE),
                Pagination.getNewOrder("value", Boolean.FALSE) // 按照奖品价值排名
        });
        return prizeDAO.findAllWithNotDraw(pagination);
    }

    public List<Prize> findByTypeAndNotWithdraw(int type) {
        return prizeDAO.findByTypeAndNotWithdraw(type);
    }


    @Autowired
    private PrizeDAO prizeDAO;
}
